package com.lanou3g.myapplication.activity.singleton.activity;

import android.app.Application;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.android.volley.toolbox.NetworkImageView;
import com.lanou3g.myapplication.R;
import com.lanou3g.myapplication.activity.singleton.VolleySingleton;
import com.lanou3g.myapplication.activity.singleton.activity.BaseActivity;
import com.lanou3g.myapplication.adapter.DetalisImageAdapter;
import com.lanou3g.myapplication.bean.BeanData;

import java.io.Serializable;
import java.text.FieldPosition;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/1/15.
 */
public class DetalisImageActivity extends BaseActivity {
    private ViewPager viewPager;
    private List<BeanData> data;
    private List<View> datas;
    private TextView textView;
    private DetalisImageAdapter adapter;

    @Override
    protected int setLayout() {

        return R.layout.detalis_image_viewpager;
    }

    @Override
    protected void initView() {
        VolleySingleton.getInstance();
        datas = new ArrayList<>();
        data = new ArrayList<>();
        viewPager = (ViewPager) findViewById(R.id.detalis_image_viewpager);

        Intent intent = getIntent();
        int position = intent.getIntExtra("position", 0);
        data = (List<BeanData>) intent.getSerializableExtra("data");
//TODO
        // Log.d("DetalisImageActivity", "position:" + position);
        int imageSize = data.get(position).getImageSize();
        Log.d("DetalisImageActivity", "!!!!!!!!!imageSize:" + imageSize);
        for (int i = 0; i < imageSize; i++) {
            View view = LayoutInflater.from(this).inflate(R.layout.activity_detalis_image, null);
            NetworkImageView networkImageView = (NetworkImageView) view.findViewById(R.id.detalis_image_iv);
            textView = (TextView) view.findViewById(R.id.detalis_image_tv);
            String detalisImageUrl = data.get(position).getDetailsImageUrl().get(i);
            String title = data.get(position).getTitle();
            Log.d("DetalisImageActivity", data.get(position).getDetailsImageUrl().get(i));
            // Log.d("DetalisImageActivity", "i:" + detalisImageUrl);

            networkImageView.setDefaultImageResId(R.mipmap.loading);
            networkImageView.setErrorImageResId(R.mipmap.failure);
            networkImageView.setImageUrl(detalisImageUrl, VolleySingleton.getImageLoader());
            textView.setText(title);
            datas.add(view);

        }
        adapter = new DetalisImageAdapter(datas);
        viewPager.setAdapter(adapter);


    }

    @Override
    protected void initData() {

    }
}
